home *** CD-ROM | disk | FTP | other *** search
- {
-
- QSORT.INC
-
- (c) 1985 Renaissance Software
-
-
- Quicksort Algorithm
- }
-
- procedure partition( min,max :integer; { min=lower bounds }
- var pl :integer; { max=upper bounds }
- var table :sortarray); { table=data to sort }
-
-
- { if you want to know }
- var { what's going on in }
- j :integer; { this block then you'll }
- parted :boolean; { have to shell out the }
- temp :arrayptr; { 35 bucks for Kunth vol.3 }
-
- begin {partition}
- j:=min+1;
- pl:=max;
- parted:=false;
- repeat
- while not ((table[j]^>table[min]^) or (j>=pl))
- do j:=j+1;
- while not (table[pl]^<=table[min]^)
- do pl:=pl-1;
- if (pl<=j) then begin
- temp:=table[min];
- table[min]:=table[pl];
- table[pl]:=temp;
- parted:=true;
- end
- else begin
- temp:=table[j];
- table[j]:=table[pl];
- table[pl]:=temp;
- j:=j+1;
- pl:=pl-1;
- end;
- until parted;
- end; {partition}
-
- {
- ---------------------------------------------------------------------------
- }
- { min=lower bounds }
- procedure qsort( min,max :integer; { max=upper bounds }
- var table :sortarray); { table=data to sort }
-
- var
- pl:integer;
-
-
- begin {qsort}
- if max>min then begin
- partition(min,max,pl,table);
- qsort(min,pl-1,table); { qsort is recursive }
- qsort(pl+1,max,table); { comments aren't }
- end;
- end; {qsort}
-
- {
- ---------------------------------------------------------------------------
- }
-